package com.abc.invoke.server.db.session;

import com.abc.invoke.server.db.system.SystemBackend;
import com.abc.invoke.server.db.user.UserBackend;
import com.abc.invoke.server.service.UserSession;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;

public class SpringInvokerDBSession implements SpringInvokerBackendSession {

	private final Supplier<SpringInvokerBackendContainer> container;
	private final UserSession userSession;

	public SpringInvokerDBSession(UserSession userSession) {
		container = Suppliers.memoize(new Supplier<SpringInvokerBackendContainer>() {
			public SpringInvokerBackendContainer get() {
				final SpringInvokerBackendContainer innerContainer = new SpringInvokerBackendContainer(
						SpringInvokerDBSession.this);
				innerContainer.createPRs();
				return innerContainer;
			}
		});

		this.userSession = userSession;
	}

	@Override
	public UserBackend getUserBackend() {
		// TODO Auto-generated method stub
		return (UserBackend)this.container.get().getLegacyService(UserBackend.class);
	}

	@Override
	public SystemBackend getSystemBackend() {
		// TODO Auto-generated method stub
		return (SystemBackend)this.container.get().getLegacyService(SystemBackend.class);
	}
}
